
/***********************************************************************
 * SpaceGame class
 * 
 * Implements the game state and the game initialization
 *
 * Signature:
 *  public static Clock clock ();
 *  public static boolean isGodMode ();
 *  public static void toggleGodMode ();
 *  public static Map map ();
 *  public static void updateMap (Map newmap);
 *  public static Player me ();
 *  public static void main (String[] argv);
 ***********************************************************************/

import java.util.*;
import java.io.*;

public class SpaceGame {

    private static int xSize = 30;
    private static int ySize = 20;
  
    private static Map gameMap = Map.empty(xSize,ySize);
    private static Player me;
    private static Clock clock = Clock.create(0); 

    public static Clock clock () { 
	return clock;
    }

    private static boolean godMode = false;

    public static boolean isGodMode () {
	return godMode;
    }
    
    public static void toggleGodMode () {
	if (godMode)
	    godMode = false;
	else
	    godMode = true;
    }

    public static Map map () {
	return gameMap;
    }

    public static void updateMap (Map m) {
	if (!m.size().equals(gameMap.size()))
	    throw new IllegalArgumentException("SpaceGame.updateMap()");
	gameMap = m;
    }

    public static Player me () {
	return me;
    }

    /*
    public static Map mapFromArray (int xsize, int ysize, 
				    Artifact[] art, int min, int max) {
	if (min==max)
	    return Map.artifact(xsize,ysize,art[min]);
	return Map.merge(mapFromArray(xsize,ysize,art,min,(max-min)/2+min),
			 mapFromArray(xsize,ysize,art,(max-min)/2+min+1,max));
    }
    */

    public static void main (String[] argv) {
	/*
	  if (argv.length > 0 && argv[0].equals("--debug"))
	  World.setDebugFlag(true);
	*/

	
	System.out.println("The CS 3500 Space Game, v1.1 (November 2009)");
	System.out.println("Type ? for a list of commands");

	me = Player.create("Defiant",Coord.create(10,10),100);

	Planet.create("Euphor",Coord.create(20,8));
	Ship.create("Arcadia",Coord.create(10,1),50);
	Star.create("Rao",Coord.create(11,11));
	Base.create("Babylon 5",Coord.create(25,3),100);
	Star.create("Sol",Coord.create(0,0));
	AutonomousEnemy.create("Cylon",Coord.create(20,10),100);

	
	//    // Register this action first
	//    // This will be the first thing executed at every turn
	//    Clock.registerAction(new PrintTickAction());
	
	//    // Create the world
	//    createWorld("blubbering-fool");
	
	//    // Create the vocabulary to control artifacts
	//    createVocabulary();

	clock().registerObserver(TimeReporter.create());
	
	InteractionLoop loop = InteractionLoop.create();
	loop.registerCommand(Quit.create());
	loop.registerCommand(Scan.create());
	loop.registerCommand(God.create());
	loop.registerCommand(Wait.create());
	loop.registerCommand(Move.create());
	loop.registerCommand(Fire.create());
	loop.registerCommand(Orbit.create());
	loop.run();
    }
    
}
